package com.basic.business.controller;

import com.basic.business.common.config.ValidationGroups;
import com.basic.business.model.dto.SysAccountRoleRelDto;
import com.basic.business.model.vo.SysAccountRoleRelVo;
import com.basic.business.service.SysAccountRoleRelService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import com.github.pagehelper.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;

/**
 * 登录账号 和 角色关系表(SysAccountRoleRel)表控制层
 *
 * @author huage
 * @since 2021-07-21 14:21:28
 */
@Api(tags = "账号和角色关联关系")
@RestController
@RequestMapping("/sysAccountRoleRel")
public class SysAccountRoleRelController {

    @Resource
    private SysAccountRoleRelService sysAccountRoleRelService;

    @ApiOperation(value = "通过id查询单条数据 登录账号 和 角色关系表")
    @ApiImplicitParam(name = "id", value = "SysAccountRoleRel id", dataType = "Integer", paramType = "path", required = true)
    @GetMapping("/findById/{id}")
    public SysAccountRoleRelVo findById(@Min(value = 1) @PathVariable(value = "id") Integer id) {
        return this.sysAccountRoleRelService.findById(id);
    }

    @ApiOperation(value = "查询多条数据 登录账号 和 角色关系表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "path", required = true),
            @ApiImplicitParam(name = "pageSize", value = "查询条数", dataType = "int", paramType = "path", required = true)
    })
    @PostMapping(value = "/findPageList/{pageNum}/{pageSize}")
    public PageInfo<SysAccountRoleRelVo> findPageList(@RequestBody SysAccountRoleRelDto sysAccountRoleRelDto, @PathVariable(value = "pageNum") int pageNum, @PathVariable(value = "pageSize") int pageSize) {
        return this.sysAccountRoleRelService.findPageList(sysAccountRoleRelDto, pageNum, pageSize);
    }

    @ApiOperation(value = "新增数据 登录账号 和 角色关系表")
    @PostMapping("/add")
    public SysAccountRoleRelVo add(@Validated(ValidationGroups.Save.class) @RequestBody SysAccountRoleRelDto sysAccountRoleRelDto) {
        return this.sysAccountRoleRelService.add(sysAccountRoleRelDto);
    }

    @ApiOperation(value = "修改数据 登录账号 和 角色关系表Dto")
    @ApiImplicitParam(name = "id", value = "SysAccountRoleRel id", dataType = "long", paramType = "query", required = true)
    @PatchMapping("/modify")
    public SysAccountRoleRelVo modify(@Validated(ValidationGroups.Update.class) @RequestBody SysAccountRoleRelDto sysAccountRoleRelDto) {
        return this.sysAccountRoleRelService.modify(sysAccountRoleRelDto);
    }

    @ApiOperation(value = "通过主键删除数据 登录账号 和 角色关系表")
    @ApiImplicitParam(name = "id", value = "SysAccountRoleRel id", dataType = "Integer", paramType = "path", required = true)
    @DeleteMapping("/remove/{id}")
    public boolean remove(@Min(value = 1) @PathVariable(value = "id") Integer id) {
        return this.sysAccountRoleRelService.remove(id);
    }

}
